package com.atguigu.yygh.order.controller;


import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.common.util.JwtHelper;
import com.atguigu.yygh.enums.OrderStatusEnum;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.order.service.OrderInfoService;
import com.atguigu.yygh.vo.order.OrderCountQueryVo;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-09-05
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation(value = "远程调用--条件查询某段时间内的预约统计数量")
    @PostMapping("/statistics")
    public Map<String,Object> getCount(@RequestBody OrderCountQueryVo orderCountQueryVo){
        return orderInfoService.getCount(orderCountQueryVo);
    }

    @ApiOperation(value = "取消预约")
    @PutMapping("/cancelOrder/{orderId}")
    public R cancelOrder(@PathVariable Long orderId) {
        orderInfoService.cancelOrder(orderId);
        return R.ok();
    }

    @ApiOperation(value = "提交订单")
    @PostMapping("/submitOrder/{scheduleId}/{patientId}")
    public R submitOrder(@PathVariable String scheduleId,
                         @PathVariable Long patientId) {
        Long orderId = orderInfoService.submitOrder(scheduleId, patientId);
        return R.ok().data("orderId", orderId);
    }

    @ApiOperation(value = "带条件的分页查询订单信息")
    @GetMapping("/{pageNum}/{pageSize}")
    public R getOrderPage(@PathVariable Integer pageNum,
                          @PathVariable Integer pageSize,
                          OrderQueryVo orderQueryVo,
                          @RequestHeader String token) {
        Long userId = JwtHelper.getUserId(token);
        Page<OrderInfo> page = orderInfoService.getOrderPage(pageNum, pageSize, userId, orderQueryVo);
        return R.ok().data("page", page);
    }

    @ApiOperation(value = "订单详情信息")
    @GetMapping("/{orderId}")
    public R detail(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderInfoService.detail(orderId);
        return R.ok().data("orderInfo", orderInfo);
    }

    @ApiOperation(value = "获取状态列表信息")
    @GetMapping("/list")
    public R getStatusList() {
        List<Map<String, Object>> statusList = OrderStatusEnum.getStatusList();
        return R.ok().data("list", statusList);
    }
}

